﻿@{
    ViewBag.Title = "Quản lí đối tác";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
}
<script type="text/javascript">
    $(document).ready(function () {
        $(".active-tab").removeClass("active-tab");
        $("a[rel=rel-ads]").parent().parent().css("display", "block");
        $("a[rel=rel-ads]").parent().parent().prev().addClass("active-tab");
        $("a[rel=rel-ads]").addClass("active-tab");
    });
    </script>
<script type="text/javascript">
     $(document).ready(function () {
       
         var url = "/Partner/getPartnerJson";
         var rowID = 0;
         var source = {
             datatype: "json",
             datafields: [
                                { name: 'PartnerID' },
                                { name: 'PartnerGroupName' },
                                { name: 'PartnerName' },
                                { name: 'PartnerImg' },
                                { name: 'PartnerUrl' },
                         ],
             id: 'PartnerID',
             url: url
         };
         var imagerenderer = function (row, datafield, value) {
             return '<img style="margin:10px;10px;10px;10px;" height="50" width="150" src="/content/upload/images/' + value + '"/>';
         }
         var cellsrenderer = function (row, columnfield, value, defaulthtml, columnproperties) {
         
            return '<span style="margin: 4px;font-weight:bold;display:block; ' + columnproperties.cellsalign + '; color: #2069b4;">' + value + '</span>';
             
         }
        
         var InteresRate = function (row, columnfield, value, defaulthtml, columnproperties) {

             return '<span style="display:block; text-align:center;">' + value + ' %</span>';

         }
         $("#grid_news").jqxGrid({
             width: '100%',
             source: source,
             rowsheight: 70,
             autoheight: true,
             pageable: true,
             sortable: true,
             altrows: true,
             enabletooltips: true,
             selectionmode: 'multiplecellsextended',
             columns: [
            { text: 'ID', datafield: 'PartnerID', width: 55 },
            { text: 'Nhóm đối tác', datafield: 'PartnerGroupName', width: 200, cellsrenderer: cellsrenderer },
            { text: 'Tên đối tác', datafield: 'PartnerName', width: 250, cellsrenderer: cellsrenderer },
            { text: 'Logo', datafield: 'PartnerImg', width: 170, height: 70, cellsrenderer: imagerenderer },
            { text: 'Link', datafield: 'PartnerUrl', width: 220 },
            { text: 'Edit', datafield: 'Edit', columntype: 'button', width: 70, cellsrenderer: function () {
            return "Edit";
            }, buttonclick: function (editrow) {

            var dataRecord = $("#grid_news").jqxGrid('getrowdata', editrow);

            window.location = "/Partner/UpdatePartner/" + dataRecord.PartnerID;


        }
        },

            { text: 'Remove', datafield: 'Delete', columntype: 'button', width: 70, cellsrenderer: function () {
                return "Delete";
            }, buttonclick: function (editrow) {

                var comfim = confirm("Bạn có muốn xóa không?");
                if (comfim) {
                    var dataRecord = $("#grid_news").jqxGrid('getrowdata', editrow);
                    $.ajax({
                        type: "POST",
                        url: "/Partner/DeletePartner",
                        datatype: "json",
                        data: { PartnerID: dataRecord.PartnerID },
                        success: function (result) {
                            if (result["Status"] == "OK") {
                                alert("Xóa thành công");
                                $("#grid_news").jqxGrid({ source: source });
                            }
                            else {

                                alert("Xóa thất bại");
                            }
                        }
                    });
                }


            }
            }
        ]
         });

     });

</script>
<div class="content-module-heading cf">
					
						<h3 class="fl">Quản lí đối tác</h3>
						<span class="fr expand-collapse-text">Thu nhỏ</span>
						<span class="fr expand-collapse-text initial-expand">Mở rộng</span>
					
					</div> <!-- end content-module-heading -->
					
					
					<div class="innerLR">
<div id="grid_news"></div>
                        </div>

